<template>
  <div id="sealreview">
    <div class="list-container">
      <div class="tables">
        <el-table
          :data="tableData"
          class="table"
          height="100%"
          ref="jdjgTable"
          @sort-change="sortChange"
          :header-cell-style="{
            padding: '0px',
            background: 'linear-gradient(0deg, #F4F6F9, #EAECF4, #F3F6F9)'
          }"
          :row-class-name="tabRowClassName"
          header-row-class-name="mapTable_th"
        >
          <el-table-column width="60" align="center" type="index" :index="addIndex" label="序号">
            <el-table-column width="60" align="center" type="index" label="检索"> </el-table-column>
          </el-table-column>
          <el-table-column label="印章名称" align="center" width="150">
            <el-table-column width="150" align="center" sortable="custom" prop="sealName">
              <template slot="header" align="center" slot-scope="{}">
                <div class="searchBox" @click.stop>
                  <el-input v-model.trim="searchPositionName" @change="getDataChange"></el-input>
                </div>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="印章类型" align="center" width="150">
            <el-table-column width="150" align="center" sortable="custom" prop="sealType">
              <template slot="header" align="center" slot-scope="{}">
                <div class="searchBox" @click.stop>
                  <el-input v-model.trim="searchPositionName" @change="getDataChange"></el-input>
                </div>
              </template>
              <template slot-scope="scope">
                <div class="">
                  {{ scope.row.sealType === 1 ? '企业章' : '私章和法人章' }}
                </div>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="开票公司名称" align="center" width="150">
            <el-table-column width="150" align="center" sortable="custom" prop="rise">
              <template slot="header" align="center" slot-scope="{}">
                <div class="searchBox" @click.stop>
                  <el-input v-model.trim="searchPositionName" @change="getDataChange"></el-input>
                </div>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="创建人" align="center" width="180">
            <el-table-column width="180" align="center" sortable="custom" prop="createBy">
              <template slot="header" align="center" slot-scope="{}">
                <div class="searchBox" @click.stop>
                  <el-input v-model.trim="searchPositionName" @change="getDataChange"></el-input>
                </div>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="创建时间" align="center" width="180">
            <el-table-column width="180" align="center" sortable="custom" prop="createTime">
              <template slot="header" align="center" slot-scope="{}">
                <div class="searchBox" @click.stop>
                  <el-input v-model.trim="searchPositionName" @change="getDataChange"></el-input>
                </div>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="状态" align="center" width="100">
            <el-table-column align="center" prop="auditStatus" width="100">
              <template slot-scope="scope">
                <div class="">
                  {{ scope.row.auditStatus === 0 ? '未审核' : scope.row.auditStatus === 1 ? '审核通过' : '审核驳回' }}
                </div>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="操作" align="center" fixed="right" width="80">
            <el-table-column align="center" width="80">
              <template slot-scope="scope">
                <div class="" v-if="scope.row.auditStatus == 0">
                  <el-button type="text" class="xg czBtn" size="small" @click="handleClick(scope.row)">
                    审核
                  </el-button>
                </div>
                <div class="" v-else>
                  <el-button type="text" class="xg czBtn" size="small" @click="handleClick(scope.row)">
                    查看
                  </el-button>
                </div>
              </template>
            </el-table-column>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <div class="pags">
      <element-pagination @getData="getPagChange" :Total="total"> </element-pagination>
    </div>
    <el-dialog
      class="supplier-dialog"
      width="1200px"
      v-if="sealVisiable"
      :center="true"
      :close-on-click-modal="false"
      title="印章审核记录"
      :before-close="closeDialog"
      :visible.sync="sealVisiable"
    >
      <div class="dialog-wrap">
        <div class="form-con">
          <div class="left">
            <el-form ref="form" class="infoForm" label-width="120px">
              <el-form-item label="印章名称："> {{ sealFrom.sealName }}</el-form-item>
              <el-form-item label="印章类型：">
                {{ sealFrom.sealType === 1 ? '企业印章' : '私人和法人印章' }}
              </el-form-item>
              <el-form-item label="印章图片：">
                <div style="font-weight: normal; color: #999">点击图片可放大查看</div>

                <el-image
                  style="width: 150px; height: 150px; cursor: pointer"
                  :src="sealFrom.sealImgUrl"
                  @click="imgCheck(sealFrom.sealImgUrl)"
                ></el-image>
              </el-form-item>
              <el-form-item label="授权书：">
                <span @click="checkPower(sealFrom.pdfUrl)" style="color: #fa7355">查看授权书</span>
              </el-form-item>
              <el-form-item label="开票公司名称："> {{ sealFrom.rise }}</el-form-item>
            </el-form>
          </div>
          <div class="right">
            <el-form ref="form" class="infoForm" style="margin-bottom: 20px" label-width="100px">
              <el-form-item label="审核状态：">
                <span style="float: left">
                  {{ sealFrom.auditStatus | reviewStateFilter }}
                </span>

                <el-image
                  style="width: 60px; height: 45px; margin-left: 20px"
                  :src="require('../../../../assets/unreviewed.png')"
                  v-if="sealFrom.auditStatus === 0"
                >
                </el-image>
                <el-image
                  style="width: 60px; height: 45px; margin-left: 20px"
                  :src="require('../../../../assets/examination_passed.png')"
                  v-else-if="sealFrom.auditStatus === 1"
                >
                </el-image>
                <el-image
                  style="width: 60px; height: 45px; margin-left: 20px"
                  :src="require('../../../../assets/review_rejected.png')"
                  v-else
                >
                </el-image>
              </el-form-item>
            </el-form>
            <div v-if="sealFrom.auditStatus === 0">
              <div style="font-size: 14px; margin-bottom: 30px">
                <p>选择<span style="color: #ff0000">驳回</span>，需填写驳回理由，等待填报人修改后再次审核。</p>
                <p>选择<span style="color: #00a2ff">通过</span>，填报的工作内容将生效，不可撤销。</p>
              </div>
              <p style="margin-bottom: 30px">
                <el-radio v-model.trim="radio" label="1">通过</el-radio>
                <el-radio v-model.trim="radio" label="2">驳回</el-radio>
              </p>
              <div style="margin-bottom: 100px">
                <el-form ref="form" class="infoForm" label-width="100px">
                  <el-form-item label="审核意见：">
                    <el-input
                      type="textarea"
                      :autosize="{ minRows: 3 }"
                      placeholder="请输入审核意见"
                      v-model.trim="auditopinion"
                    >
                    </el-input>
                  </el-form-item>
                </el-form>
              </div>
              <el-button size="small" @click="subMitBtn(sealFrom.id)"> 提交审核 </el-button>
            </div>
            <div v-else class="isreview">
              <el-form ref="form" class="infoForm" style="margin-bottom: 20px" label-width="100px">
                <el-form-item label="审核人：">
                  {{ sealFrom.reviewer }}
                </el-form-item>
                <el-form-item label="审核时间：">
                  {{ sealFrom.auditTime }}
                </el-form-item>
                <el-form-item label="审核结果：">
                  {{ sealFrom.auditStatus | reviewStateFilter }}
                </el-form-item>
                <el-form-item label="审核意见：">
                  {{ sealFrom.remark }}
                </el-form-item>
              </el-form>
            </div>
          </div>
        </div>
      </div>
    </el-dialog>
    <el-image-viewer style="z-index: 99999" v-if="showViewer" :on-close="viewerClose" :url-list="stencilUrl" />
  </div>
</template>

<script>
import ElImageViewer from 'element-ui/packages/image/src/image-viewer'
import ElementPagination from '../../../../components/ElementPagination.vue'
export default {
  components: { ElementPagination, ElImageViewer },
  data() {
    return {
      auditopinion: '',
      sealFrom: {},
      searchPositionName: '',
      total: 0,
      page: 1,
      size: 15,
      stencilUrl: [],
      showViewer: false,
      radio: null,
      sealVisiable: false,
      tableData: []
    }
  },
  mounted() {
    this.getData()
  },
  filters: {
    reviewStateFilter(val) {
      if (val === null) {
        return
      }
      return val === 0 ? '未审核' : val === 1 ? '审核通过' : '审核驳回'
    }
  },
  methods: {
    viewerClose() {
      this.showViewer = false
      this.stencilUrl = []
    },
    subMitBtn(id) {
      let flag = true
      if (this.radio) {
        if (this.radio === '2' && this.auditopinion == '') {
          this.$message.error('请填写驳回理由')
          flag = false
        }
        if (flag) {
          this.$https({
            url: '/government/sealAuditReview',
            method: 'post',
            data: {
              id: id,
              remark: this.auditopinion,
              agree: this.radio == 1 ? true : false
            }
          }).then(res => {
            if (res.code === 0) {
              this.$message.success('审核成功')
              this.radio = null
              this.sealVisiable = false
              this.sealFrom = {}
              this.getData()
            } else {
              this.$message.error(res.msg)
            }
          })
        }
      } else {
        this.$message.error('请选择审核结果')
      }
    },
    // 查看图片大图
    imgCheck(url) {
      this.stencilUrl.push(url)
      this.showViewer = true
    },
    // 在线预览文档(存在限制，公共文件才可以预览)
    checkPower(url) {
      window.open('https://view.officeapps.live.com/op/view.aspx?src=' + url)
    },
    closeDialog(done) {
      this.sealFrom = {}
      done()
    },
    handleClick(scope) {
      this.sealFrom = scope
      this.sealVisiable = true
    },
    getDataChange() {},
    getPagChange(data) {
      this.page = data.currentPage
      this.size = data.pagesize
      this.getData()
    },
    getData() {
      this.$https({
        method: 'post',
        url: '/government/sealAuditRecord',
        data: {
          page: this.page,
          size: this.size
        }
      })
        .then(res => {
          if (res.code === 0) {
            this.total = res.data.total
            this.tableData = res.data.records
          } else {
            this.$message.error(res.msg)
          }
        })
        .catch(err => {
          console.log(err)
        })
    },
    sortChange() {},
    addIndex(index) {
      return index + 1 + (this.page - 1) * this.size
    },
    tabRowClassName({ row, rowIndex }) {
      let index = rowIndex + 1
      if (index % 2 == 0) {
        return 'warning-row'
      }
    }
  }
}
</script>
<style lang="less" scoped>
#sealreview {
  height: 100%;
  .list-container {
    height: calc(100% - 62px);
    .tables {
      height: 100%;
    }
  }
  .dialog-wrap {
    width: 100%;
  }
  .form-con {
    border: 1px solid #d6d6d6;
    display: flex;
    padding: 20px 0;
    .left {
      width: 50%;
      border-right: 1px dashed #d6d6d6;
      padding: 0 50px;
    }
    .right {
      width: 50%;
      padding: 0 50px;
    }
  }
  .item {
    vertical-align: top;
    margin-right: 10px;
    font-size: 16px;
  }
  /deep/ .left {
    .el-form-item__label {
      color: #666;
    }
    .el-form-item__content {
      color: #333;
    }
  }
  .supplier-dialog {
    /deep/ .right {
      .el-form-item__label,
      .el-form-item__content {
        color: #333;
        font-size: 16px;
      }
      .el-form-item__content {
        font-weight: 600;
      }
    }
    /deep/ .el-form-item {
      margin-bottom: 0;
    }
    /deep/ .el-tabs__item {
      height: 32px;
      line-height: 30px;
    }
    /deep/ .el-button {
      width: 280px;
      color: #fff;
      background-color: #fa7355;
      border: none;
      border-radius: 5px;
    }
  }
}
</style>
